added Feb 2001 SDK
[windows-sources.git] / shared source / sscli20 / jscript / engine / scriptobjectpropertyenumerator.cs
blobccf102473ba09e4a43d85640da01c1b5e05aff86
1 // ==++==
2 //
3 //
4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
5 //
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
10 //
11 // You must not remove this notice, or any other, from this software.
12 //
13 //
14 // ==--==
16 namespace Microsoft.JScript {
18 using System;
19 using System.Collections;
20 using System.Reflection;
22 internal class ScriptObjectPropertyEnumerator : IEnumerator{
23 private ArrayList enumerators;
24 private ArrayList objects;
25 private int index;
26 private SimpleHashtable visited_names;
28 internal ScriptObjectPropertyEnumerator(ScriptObject obj){
29 obj.GetPropertyEnumerator(this.enumerators = new ArrayList(), this.objects = new ArrayList());
30 this.index = 0;
31 this.visited_names = new SimpleHashtable(16);
34 public virtual bool MoveNext(){
35 if (this.index >= this.enumerators.Count)
36 return false;
37 IEnumerator ienum = (IEnumerator)this.enumerators[this.index];
38 bool result = ienum.MoveNext();
39 if (!result){
40 this.index++; return this.MoveNext();
42 Object ob = ienum.Current;
43 String pname;
44 FieldInfo field = ob as FieldInfo;
45 if (field != null){
46 JSPrototypeField pfield = ob as JSPrototypeField;
47 if (pfield != null && pfield.value is Missing)
48 return this.MoveNext();
49 pname = field.Name;
50 Object val = field.GetValue(this.objects[this.index]);
51 if (val is Missing)
52 return this.MoveNext();
53 }else if (ob is String)
54 pname = (String)ob;
55 else if (ob is MemberInfo)
56 pname = ((MemberInfo)ob).Name;
57 else
58 pname = ob.ToString();
59 if (this.visited_names[pname] != null)
60 return this.MoveNext();
61 this.visited_names[pname] = pname;
62 return true;
65 public virtual Object Current{
66 get{
67 Object ob = ((IEnumerator)this.enumerators[this.index]).Current;
68 if (ob is MemberInfo)
69 return ((MemberInfo)ob).Name;
70 else
71 return ob.ToString();
75 public virtual void Reset(){
76 this.index = 0;
77 foreach(System.Collections.IEnumerator e in this.enumerators)
78 e.Reset();
79 this.visited_names = new SimpleHashtable(16);